library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
data_analytic<- readRDS("../../../../test/data/interim/analytic2023_c1.rds")
Motor vehicle deaths raw(v039):Number of motor vehicle crash deaths per 100,000 population. Drive along to work (v067):Percentage of the workforce that drives alone to work. Long Commute Alone (v137): Among workers who commute in their car alone, the percentage that commute more than 30 minutes. No break down by race for 067 & 137
ggplot(data_analytic, aes(y = v005_rawvalue, x = v039_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Number of motor vehicle crash deaths per 100,000 population.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
## ℹ Please use the `linewidth` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 457 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 457 rows containing missing values (`geom_point()`).
ggplot(data_analytic, aes(y = v005_rawvalue, x = v067_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Percentage of the workforce that drives alone to work.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 71 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 71 rows containing missing values (`geom_point()`).
ggplot(data_analytic, aes(y = v005_rawvalue, x = v137_rawvalue))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste("Among workers who commute in their car alone, the percentage that commute more than 30 minutes.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 71 rows containing non-finite values (`stat_smooth()`).
## Removed 71 rows containing missing values (`geom_point()`).
v039_xaxis_vars <- c("v039_race_hispanic", "v039_race_white", "v039_race_asian", "v039_race_aian", "v039_race_black")
for(var in v039_xaxis_vars){
va148byracegraph <- ggplot(data_analytic, aes_string(y = "v005_rawvalue", x = var))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var, ":Number of motor vehicle crash deaths per 100,000 population.
.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va148byracegraph)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2649 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2649 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 638 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 638 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3037 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3037 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3059 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3059 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2449 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2449 rows containing missing values (`geom_point()`).
v005_race_yaxis <- c("v005_race_hispanic","v005_race_white","v005_race_asian","v005_race_aian","v005_race_black")
v039_xaxis_vars <- c("v039_race_hispanic", "v039_race_white", "v039_race_asian", "v039_race_aian", "v039_race_black")
for(i in 1:length(v039_xaxis_vars)){
var_x <- v039_xaxis_vars[i]
var_y <- v005_race_yaxis[i]
v039byracegraph <-ggplot(data_analytic, aes_string(y = paste0("log(",var_y, ")"), x = paste0("log(",var_x,")")))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var_x, ":income median.")) +
ylab(paste(var_y, ":Preventable Hospital Stays"))+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(v039byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2674 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2674 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 639 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 639 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3037 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3037 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 3062 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 3062 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2452 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2452 rows containing missing values (`geom_point()`).
v067_xaxis_vars <- c("v067_race_hispanic", "v067_race_white", "v067_race_asian", "v067_race_aian", "v067_race_black")
#Race: Hispanic
for(var in v067_xaxis_vars){
va148byracegraph <- ggplot(data_analytic, aes_string(y = "v005_rawvalue", x = var))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var, ":Percentage of the workforce that drives alone to work.")) +
ylab("Preventable Hospital Stays")+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(va148byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 1864 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 1864 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 123 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 123 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2556 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2556 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2763 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2763 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2049 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2049 rows containing missing values (`geom_point()`).
v005_race_yaxis <- c("v005_race_hispanic","v005_race_white","v005_race_asian","v005_race_aian","v005_race_black")
v067_xaxis_vars <- c("v067_race_hispanic", "v067_race_white", "v067_race_asian", "v067_race_aian", "v067_race_black")
for(i in 1:length(v067_xaxis_vars)){
var_x <- v067_xaxis_vars[i]
var_y <- v005_race_yaxis[i]
v067byracegraph <-ggplot(data_analytic, aes_string(y = paste0("log(",var_y, ")"), x = paste0("log(",var_x,")")))+
geom_point(color="green", alpha =0.5)+
geom_smooth()+
xlab(paste(var_x, ":income median.")) +
ylab(paste(var_y, ":Preventable Hospital Stays"))+
theme(panel.background = element_rect(fill = "black"),
plot.background = element_rect(fill = "black"),
panel.grid.major = element_line(color = "white", size = 0.1),
panel.grid.minor = element_line(color = "white", size = 0.05),
text = element_text(color = "white"))
print(v067byracegraph)
}
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2303 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2303 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 138 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 138 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2788 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2788 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2895 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2895 rows containing missing values (`geom_point()`).
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 2103 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 2103 rows containing missing values (`geom_point()`).